package com.example.springbean.pkg;

import org.springframework.beans.BeansException;
import org.springframework.beans.factory.*;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import java.io.Serializable;

/**
 * B
 *
 * @author 15871
 */
@Component
public class BeanTest implements BeanNameAware,
        Serializable, ApplicationContextAware,
        BeanFactoryAware, InitializingBean, DisposableBean {

    private String name;

    private BeanTest() {
        System.out.println("实例化BeanTest");
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getName() {
        return name;
    }

    @Override
    public void setBeanName(String s) {
        System.out.println("设置beanName " + s);
    }

    @Override
    public void setBeanFactory(BeanFactory beanFactory) throws BeansException {
        System.out.println("BeanFactory" + "哈哈");
    }

    @Override
    public void afterPropertiesSet() throws Exception {
        System.out.println("afterPropertiesSet  初始化方法后");
    }

    @Override
    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
        System.out.println("applicationContextAware");
    }


    // PostConstruct在构造函数之后执行，init（）方法之前执行
    @PostConstruct
    public void postConstruct() {
        System.out.println("postConstruct");
    }

    @Override
    public String toString() {
        return "BeanTest{" +
                "name=" + name +
                '}';
    }

    @Override
    public void destroy() throws Exception {
        System.out.println("销毁beanTest");
    }
}
